<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8'>
        <meta name='viewport' content="width=device-width,initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
        <title>均摊时间复杂度分析</title>
    </head>
    <body>
        <pre  class="language-JavaScript">
            <code>
                class MyVector {
                    constructor() {
                        this.data = new Array(10);
                        this.capacity = 10;
                        this.size = 0;
                    }
                    push_back(e) {
                        if(this.size === this.capacity) {
                            this.resize(2 * this.capacity);
                        }
                        data[this.size ++] = e;
                    }
                    pop_back() {
                        if(this.size <= 0) return;
                        let ret = this.data[this.size - 1];
                        this.size --;
                        if(size === capacity / 4) 
                           this.resize(capacity / 2);
                        return ret;
                    }
                    resize(newCapacity) {
                        let newData = new ARray(newCapacity);
                        for(let i = 0; i < this.size; i ++) {
                            newData[i] = this.data[i];
                        }
                        delete this.data;
                        this.data = newData;
                        this.capacity = newCapacity;
                    }
                }
            </code>
        </pre>
        <script>
            class MyVector {
                constructor() {
                    this.data = new Array(10);
                    this.capacity = 10;
                    this.size = 0;
                }
                push_back(e) {
                    if(this.size === this.capacity) {
                        this.resize(2 * this.capacity);
                    }
                    data[this.size ++] = e;
                }
                pop_back() {
                    if(this.size <= 0) return;
                    let ret = this.data[this.size - 1];
                    this.size --;
                    if(size === capacity / 4) 
                       this.resize(capacity / 2);
                    return ret;
                }
                resize(newCapacity) {
                    let newData = new ARray(newCapacity);
                    for(let i = 0; i < this.size; i ++) {
                        newData[i] = this.data[i];
                    }
                    delete this.data;
                    this.data = newData;
                    this.capacity = newCapacity;
                }
            }
        </script>
    </body>
</html>